import os

def remove_spaces_and_newlines(directory):
    for filename in os.listdir(directory):
        if filename.endswith('.txt'):
            file_path = os.path.join(directory, filename)
            with open(file_path, 'r', encoding='utf-8') as file:
                content = file.read()
            content = content.replace(' ', '').replace('\n', '')
            with open(file_path, 'w', encoding='utf-8') as file:
                file.write(content)

if __name__ == "__main__":
    remove_spaces_and_newlines('D:\\wen\\1')
